const MyPromise = require('./my-promise')

let p1 = new MyPromise(function (resolve, reject) {
  setTimeout(() => {
    resolve('p1 success')
    // reject('p1 fail')
  }, 3000)
})
p1.then(
  (value) => {
    console.log('first then onSuccess:', value)
  },
  (e) => {
    console.log('first then onRejected:', e)
  }
)

let p2 = new MyPromise(function (resolve, reject) {
  resolve('p2 success')
  // reject('p2 fail')
})
p2.then(
  (value) => {
    console.log('second then onSuccess:', value)
  },
  (e) => {
    console.log('second then onRejected:', e)
  }
)
// .finally(() => {
//   console.log('p2 finally')
// })
// .then((value) => {
//   console.log('p2 after finally:', value)
// })
// .catch((e) => {
//   console.log('p2 after finally catch:', e)
// })

MyPromise.all([p1, p2]).then(
  (results) => {
    console.log('MyPromise.all fullfilled:', results)
  },
  (e) => {
    console.log('MyPromise.all rejected:', e)
  }
)
